package com.sx.manage.service.consumer;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.sx.cache.Cache;
import com.sx.common.util.NumberUtil;
import com.sx.common.util.http.HttpPoolManager;
import com.sx.common.util.http.constants.RedisConstants;
import com.sx.common.util.json.JackJsonUtil;
import com.sx.common.util.message.MessageForm;
import com.sx.common.util.message.MessageModel;
import com.sx.common.util.message.MessageType;
import com.sx.common.vo.BaseVO;
import com.sx.manage.biz.consumer.IMConsumerEditInfoBiz;
import com.sx.manage.biz.consumer.bank.IMConsumerBankMapBiz;
import com.sx.manage.biz.consumer.info.IMNetworkPersonConsumerBiz;
import com.sx.manage.biz.consumer.relation.IMConsumerDataRelationBiz;
import com.sx.manage.biz.data.auth.IMDataAuthorityBiz;
import com.sx.manage.listener.MCacheListener;
import com.sx.manage.service.bank.IMBaseBankService;
import com.sx.manage.service.bank.IMBaseConsumerBankMapService;
import com.sx.manage.service.bank.IMConsumerBankMapService;
import com.sx.manage.service.city.IMBaseCityService;
import com.sx.manage.service.consumer.info.IMConsumerOperationInfoService;
import com.sx.manage.service.consumer.network.IMBasePersonConsumerNetworkService;
import com.sx.manage.service.consumer.util.MConsumerWebServiceUtil;
import com.sx.manage.service.consumer.util.WebConsumerEditUtil;
import com.sx.manage.service.sys.IMBaseSystemConfigInfoService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.manage.util.ExcelUtils;
import com.sx.manage.util.HttpUtil;
import com.sx.manage.util.WebLogUtil;
import com.sx.manage.util.WebServiceUtil;
import com.sx.manage.util.WebServiceUtils;
import com.sx.model.constants.MDataStatusType;
import com.sx.model.constants.MSystemConstants;
import com.sx.model.constants.type.account.MAccountNumStatus;
import com.sx.model.constants.type.bank.MBindCardStatus;
import com.sx.model.constants.type.bank.MOutCardType;
import com.sx.model.constants.type.bank.MUserInfoBankValidate;
import com.sx.model.constants.type.bank.MUsingStatus;
import com.sx.model.constants.type.consumer.MConsumerDataRelationType;
import com.sx.model.constants.type.data.auth.MDataAuthPath;
import com.sx.model.constants.type.function.MFuncType;
import com.sx.model.constants.type.log.MLogOperType;
import com.sx.model.exception.MRollbackException;
import com.sx.model.manage.mybatis.form.bank.MConsumerBankMapForm;
import com.sx.model.manage.mybatis.form.consumer.MConsumerDataRelationForm;
import com.sx.model.manage.mybatis.form.consumer.MPersonalConsumerNetworkForm;
import com.sx.model.manage.mybatis.form.data.auth.MDataAuthorityForm;
import com.sx.model.manage.mybatis.form.sys.MSystemConfigInfoForm;
import com.sx.model.manage.mybatis.vo.bank.MPayBankVO;
import com.sx.model.manage.mybatis.vo.consumer.MConsumerBankMapVO;
import com.sx.model.manage.mybatis.vo.consumer.MConsumerDataRelationVO;
import com.sx.model.manage.mybatis.vo.consumer.MConsumerOperationInfoVO;
import com.sx.model.manage.mybatis.vo.consumer.MPersonalConsumerNetworkVO;
import com.sx.model.manage.mybatis.vo.consumer.MPersonalConsumerVO;
import com.sx.model.manage.mybatis.vo.consumer.MVerifOpenAccountVO;
import com.sx.model.manage.mybatis.vo.consumer.login.MConsumerLoginVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;
import com.sx.model.manage.mybatis.vo.result.ResultVerifyVO;
import com.sx.model.manage.mybatis.vo.sys.MSysConfigVO;
import com.sx.model.manage.mybatis.vo.util.MsgVO;
import com.sx.model.manage.mybatis.web.vo.huaxia0.B2BOpenAccountVO;

import net.sf.json.JSONObject;

/**
 * 个人用户
 * 
 * @author lenovo
 *
 */
@Service("consumerWebServiceImpl")
@SuppressWarnings("rawtypes")
public class MConsumerWebServiceImpl {

	private Logger log = LoggerFactory.getLogger(this.getClass());

	/** session超时设置 */
	public static final Integer HTTP_TIME_OUT = 50000;

	@Resource(name = "redisCache")
	private Cache cache;
	@Resource
	private WebLogUtil webLogUtil;
	// 用户信息新接口
	@Resource(name = "mNetworkPersonConsumerBizImpl")
	public IMNetworkPersonConsumerBiz mNetworkPersonConsumerBizImpl;

	// 系统参数配置
	@Resource(name = "mBaseSystemConfigInfoServiceImpl")
	private IMBaseSystemConfigInfoService mBaseSystemConfigInfoServiceImpl;
	// 账户service
	//@Resource(name = "accountService")
	//private IAccountServiceInterface accountService;
	// 用户银行关系
	@Resource(name = "mBaseConsumerBankMapServiceImpl")
	private IMBaseConsumerBankMapService mBaseConsumerBankMapServiceImpl;
	// 用户银行关系
	@Resource(name = "consumerBankMapServiceImpl")
	private IMConsumerBankMapService consumerBankMapServiceImpl;
	// 银行信息
	@Resource(name = "mBaseBankServiceImpl")
	private IMBaseBankService mBaseBankServiceImpl;
	// 城市信息
	@Resource(name = "mBaseCityServiceImpl")
	private IMBaseCityService mBaseCityServiceImpl;
	// 用户关系数据
	@Resource(name = "mConsumerDataRelationBizImpl")
	private IMConsumerDataRelationBiz mConsumerDataRelationBizImpl;

	@Resource(name = "mBasePersonConsumerNetworkServiceImpl")
	private IMBasePersonConsumerNetworkService mBasePersonConsumerNetworkServiceImpl;
	// 用户银行信息biz
	@Resource(name = "mConsumerBankMapBizImpl")
	private IMConsumerBankMapBiz mConsumerBankMapBizImpl;

	@Resource(name = "httppoolmanager")
	private HttpPoolManager httpPoolManager;
	// 用户信息修改
	@Resource(name = "mConsumerEditInfoBizImpl")
	private IMConsumerEditInfoBiz mConsumerEditInfoBizImpl;

	// 数据下载权限申请
	@Resource(name = "dataAuthorityBizImpl")
	private IMDataAuthorityBiz dataAuthorityBizImpl;
	// 扩展信息
	@Resource(name = "consumerOperationInfoServiceImpl")
	private IMConsumerOperationInfoService consumerOperationInfoServiceImpl;

	@Resource(name = "webServiceUtils")
	private WebServiceUtils webServiceUtils;
	// web端 consumer util
	@Resource(name = "consumerWebServiceUtil")
	private MConsumerWebServiceUtil consumerWebServiceUtil;

	/** 获取用户默认使用开户渠道 **/
	@SuppressWarnings("unused")
	private String queryConsumerChannelType(Long consumer_id) {
		log.info("获取用户默认渠道consumer_id={}");
		MConsumerDataRelationVO relationVO = mConsumerDataRelationBizImpl.query_by_consumer_id_and_relation_type(consumer_id, MConsumerDataRelationType.CONSUMER_PERSON_CHANNEL_TYPE).getObjVo();
		if (null == relationVO) {
			log.info("用户没有可以使用的渠道consumer_id={}", consumer_id);
			return null;
		}
		return relationVO.getRelation_string_num();
	}

	/** 用户激活 */
	public ResultBooleanVO consumersActivate(Long[] consumer_ids, MConsumerLoginVO loginConsumer) {
		log.info("用户激活consumer_ids={}", NumberUtil.arrayToStr(consumer_ids));
		ResultBooleanVO result = validateConsumerBank(consumer_ids);
		if (!result.isSuccess()) {
			log.info("用户激活验证未通过msg={}", result.getMsg());
			return result;
		}
		// 激活发送短信和邮件
		try {
			send_Sms_email_personal(consumer_ids, loginConsumer.getConsumer_id());
		} catch (Exception e) {
			log.error("激活发送短信和邮件", e);
		}
		return new ResultBooleanVO();
	}

	public ResultBooleanVO validateConsumerBank(Long[] consumer_ids) {

		ResultBooleanVO result = new ResultBooleanVO();
		// 银行信息不是默认状态的
		MsgVO msgNotDefault = new MsgVO();
		// 银行信息不存在的
		MsgVO msgNull = new MsgVO();
		MConsumerBankMapVO bankMapVO = null;
		MPersonalConsumerNetworkVO consumerVO = null;
		for (Long consumer_id : consumer_ids) {
			bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumerBankMap_for_manage(consumer_id, null);
			if (null == bankMapVO || null == bankMapVO.getId()) {// 银行卡信息不存在
				consumerVO = this.mBasePersonConsumerNetworkServiceImpl.get_consumer_by_id(consumer_id).getObjVo();
				msgNull.append(consumerVO.getConsumer_name());
				continue;
			}
			// 卡需要等待华夏回调
			if (MUsingStatus.DEFAULT_USED_WAIT.equals(bankMapVO.getStatus())) {
				consumerVO = this.mBasePersonConsumerNetworkServiceImpl.get_consumer_by_id(consumer_id).getObjVo();
				msgNotDefault.append(consumerVO.getConsumer_name());
			}
		}
		MsgVO resultMsg = new MsgVO();
		if (msgNull.getError().length() > 0) {
			msgNull.setEndMsg("银行卡信息为空");
			resultMsg.append(msgNull.getError());
		}
		if (msgNotDefault.getError().length() > 0) {
			msgNotDefault.setEndMsg("银行卡信息等待华夏审核");
			resultMsg.append(msgNotDefault.getError());
		}
		if (resultMsg.getError().length() > 0) {
			result.setSuccess(false);
			result.setMsg(resultMsg.getError());
		}
		return result;
	}

	/** 激活短信 邮件（个人用户） */
	private void send_Sms_email_personal(Long[] consumer_ids, Long userId) {
		// 判断参数是否为空
		if (0 == consumer_ids.length) {
			return;
		}
		for (int i = 0; i < consumer_ids.length; i++) {
			ResultObjectVO<MPersonalConsumerNetworkVO> perVOResult = mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_ids[i]);
			MPersonalConsumerNetworkVO personalVO = perVOResult.getObjVo();
			if (null == personalVO) {
				return;
			}
			String code = UUID.randomUUID().toString().replace("-", "");
			cache.set(RedisConstants.CONF_ACTIVATE + code, String.valueOf(consumer_ids[i]));
			cache.expire(RedisConstants.CONF_ACTIVATE + code, MSystemConstants.EXPIRE_TIME_);
			log.info("激活短信 邮件codeKey={},consumer_id={}", RedisConstants.CONF_ACTIVATE + code, consumer_ids[i]);
			log.info("激活短信 邮件codeKey={},consumer_id={}", RedisConstants.CONF_ACTIVATE + code, MSystemConstants.EXPIRE_TIME_);
			String sen_url = spellUrl(code);
			try {
				log.info("发送短信：" + personalVO.getConsumer_name() + "," + personalVO.getMobile_tel());
				send_Sms(personalVO.getMobile_tel(), sen_url, personalVO.getConsumer_name(), userId);
			} catch (Exception e) {
				log.error("发送短信出错：", e);

			}
			try {
				log.info("发送邮件：" + personalVO.getConsumer_name() + "," + personalVO.getEmail());
				send_Email(personalVO.getEmail(), personalVO.getConsumer_name(), sen_url, userId);
			} catch (Exception e) {
				log.error("发送邮件出错：", e);
			}
		}
	}

	/** 激活 短信 */
	private void send_Sms(String mobile, String sen_url, String userName, Long userId) {
		if (null == sen_url) {
			return;
		}
		if (null == userName) {
			return;
		}
		log.info("用户激活:===发送短信号码:" + mobile);
		// 发送短信

		MSystemConfigInfoForm form = new MSystemConfigInfoForm();
		form.setConfig_name(MSystemConstants.TPLID_);

		MSysConfigVO sysConfigVO = mBaseSystemConfigInfoServiceImpl.queryByIdSystemConfig(form).getObjVo();
		if (null == sysConfigVO) {
			return;
		}
		// 参数
		String tplValue = WebConsumerEditUtil.spelArg(userName, sen_url);
		if (StringUtils.isBlank(tplValue)) {
			return;
		}
		MSysConfigVO vo = mBaseSystemConfigInfoServiceImpl.queryByIdSystemConfig(new MSystemConfigInfoForm(MSystemConstants.MESSAGE_HOST_URL)).getObjVo();
		if (null == vo) {
			log.info("用户激活:===发送短信参数错误，请联系管理员配置" + MSystemConstants.MESSAGE_HOST_URL + "该参数！");
			return;
		}
		try {
			// 发送短信
			sendTplSms(mobile, Long.valueOf(sysConfigVO.getConfig_value()), new Object[] { userName, sen_url }, userId.toString(), vo.getConfig_value(), MessageType.SHORTMESSAGE);
		} catch (Exception e) {
			log.error("发送短信异常error={}", e);
		}
	}

	/** 激活 发送邮件 */
	private void send_Email(String email, String userName, String sen_url, Long userId) {
		if (null == email) {
			return;
		}
		if (null == userName) {
			return;
		}
		if (null == sen_url) {
			return;
		}
		log.info("用户激活:===发送邮件名称:" + userName + "发送邮件:" + email);
		List<String> list = new ArrayList<>();
		list.add(email);
		// 发送邮件
		MSystemConfigInfoForm form = new MSystemConfigInfoForm();
		form.setConfig_name(MSystemConstants.SUBJECT_ACTIVATE_);

		MSysConfigVO sysConfigVO = mBaseSystemConfigInfoServiceImpl.queryByIdSystemConfig(form).getObjVo();

		if (null == sysConfigVO) {
			return;
		}
		String text = MSystemConstants.EMAIL_TEMPLATE;
		text = WebConsumerEditUtil.formatValues(text, userName, sysConfigVO.getConfig_value(), sen_url);
		MSysConfigVO vo = mBaseSystemConfigInfoServiceImpl.queryByIdSystemConfig(new MSystemConfigInfoForm(MSystemConstants.MESSAGE_HOST_URL)).getObjVo();
		if (null == vo) {
			log.info("用户激活:===发送邮件参数错误，请联系管理员配置" + MSystemConstants.MESSAGE_HOST_URL + "该参数！");
			return;
		}
		log.debug("邮件==用户激活url：" + sen_url);
		// 发送短信
		sendTplEmail(null, email, sysConfigVO.getConfig_value(), text, userId.toString(), vo.getConfig_value(), MessageType.EMAIL);
	}

	/** 发送模版短信 */
	public BaseVO sendTplSms(String phone, Long tplId, Object[] tplValue, String userId, String url, MessageType messageType) {
		MessageModel message = WebConsumerEditUtil.get_shortMessage(phone, tplId, tplValue, userId, messageType);

		MessageForm messageForm = new MessageForm();
		messageForm.setMessagemodel(message);
		messageForm.setMessageTypes(new MessageType[] { messageType });
		log.info("发送短信: {}", JackJsonUtil.objToJson(messageForm));
		String result = HttpUtil.post(url, JackJsonUtil.objToJson(messageForm));
		log.info(result);
		if (StringUtils.isBlank(result)) {
			return BaseVO.createErrorMsgBykey("sj.m.user.activate.data.error");
		}
		JSONObject json = JSONObject.fromObject(result);
		boolean b = json.getBoolean("success");
		if (!b) {
			log.info("发送短信失败error={}", json.getString("msg"));
			return BaseVO.createMsg(false, json.getString("code"), json.getString("msg"));
		}
		return BaseVO.createMsg(true, json.getString("code"), json.getString("msg"));
	}

	/** 发送模版短信 */
	public BaseVO sendTplEmail(String email, String temail, String emialsub, String emialcontent, String userId, String url, MessageType messageType) {

		MessageModel message = WebConsumerEditUtil.get_emailMessage(email, temail, emialsub, emialcontent, userId, messageType);

		MessageForm messageForm = new MessageForm();
		messageForm.setMessagemodel(message);
		messageForm.setMessageTypes(new MessageType[] { messageType });
		log.info("发送邮件: {}", JackJsonUtil.objToJson(messageForm));
		String result = HttpUtil.post(url, JackJsonUtil.objToJson(messageForm));
		log.info(result);
		if (StringUtils.isBlank(result)) {
			return BaseVO.createErrorMsgBykey("sj.m.user.activate.data.error");
		}
		JSONObject json = JSONObject.fromObject(result);
		boolean b = json.getBoolean("success");
		if (!b) {
			log.info("发送邮件失败error={}", json.getString("msg"));
			return BaseVO.createMsg(false, json.getString("code"), json.getString("msg"));
		}
		return BaseVO.createMsg(true, json.getString("code"), json.getString("msg"));
	}

	/** 拼接激活用户 URL */
	private String spellUrl(String code) {
		if (null == code) {
			return null;
		}
		MSystemConfigInfoForm form = new MSystemConfigInfoForm();
		form.setConfig_name(MSystemConstants.SYSTEM_URL_);

		MSysConfigVO sysConfigVO = mBaseSystemConfigInfoServiceImpl.queryByIdSystemConfig(form).getObjVo();

		if (null == sysConfigVO) {
			return null;
		}
		return sysConfigVO.getConfig_value() + "/" + code;
	}

	/**
	 * 子账户开户 public ResultVerifyVO<MVerifOpenAccountVO> accountInfo(Long[] ids) {
	 * ResultVerifyVO<MVerifOpenAccountVO> vo = new ResultVerifyVO<>(); if (null ==
	 * ids || 0 == ids.length) { return new ResultVerifyVO<>("m.parameter.is.null");
	 * } Map<String, MPayBankVO> payMap = MCacheListener.getProvinceMap(); // 用户信息错误
	 * StringBuilder consumerBankError = new StringBuilder(); // 错误信息提示集合
	 * List<MVerifOpenAccountVO> errorList = new ArrayList<>(); for (Long id : ids)
	 * { log.info("个人开户信息 开户ID={}", id); // 获取个人信息 MPersonalConsumerNetworkVO
	 * personalNetworkVO =
	 * this.mNetworkPersonConsumerBizImpl.get_consumer_byId(id).getObjVo(); if (null
	 * == personalNetworkVO) { return new ResultVerifyVO<>(false, null,
	 * "所选用户已经有删除，请刷新数据重新选择", null); } log.info("开始获取用户银行关系"); // 获取个人与银行关系
	 * ResultObjectVO<MConsumerBankMapVO> bankMapResult =
	 * mBaseConsumerBankMapServiceImpl.query_bank_by_consumer_id(personalNetworkVO.getId());
	 * 
	 * if (!bankMapResult.isSuccess()) {
	 * consumerBankError.append(personalNetworkVO.getConsumer_name()).append(bankMapResult.getMsg()).append("\n");
	 * continue; } MConsumerBankMapVO userBankMapVO = bankMapResult.getObjVo();
	 * userBankMapVO.setCls_bank_name(payMap.get(userBankMapVO.getCls_bank_name()).getHuaxia_bank());
	 * log.info("开户前数据准备:" + JackJsonUtil.objToJson(personalNetworkVO));
	 * 
	 * // 开户 ResultObjectVO<B2BOpenAccountVO> openResult =
	 * opeanAccountHX02(personalNetworkVO, payMap,
	 * MSystemConstants.CHANNEL_TYPE_HXBV1);// 调用开户接口 // 错误信息提示 if
	 * (!openResult.isSuccess()) { MVerifOpenAccountVO errorVO = new
	 * MVerifOpenAccountVO(); errorVO.setName(personalNetworkVO.getConsumer_name());
	 * errorVO.setError_info(openResult.getMsg()); errorList.add(errorVO); continue;
	 * } // 更新银行信息 ResultBooleanVO bankResult =
	 * verification_OpenAccount(openResult.getObjVo(), personalNetworkVO,
	 * userBankMapVO); if (bankResult.isSuccess()) { MVerifOpenAccountVO errorVO =
	 * new MVerifOpenAccountVO();
	 * errorVO.setName(personalNetworkVO.getConsumer_name());
	 * errorVO.setError_info(openResult.getMsg()); errorList.add(errorVO); } }
	 * log.info("个人开户==开户处理结果=已经返回=="); if (!errorList.isEmpty()) {
	 * vo.setSuccess(false); vo.setData(errorList); } return vo; }
	 */

	/**
	 * 开户返回 public ResultBooleanVO verification_OpenAccount(B2BOpenAccountVO
	 * openAccountVO, MPersonalConsumerNetworkVO personalNetworkVO,
	 * MConsumerBankMapVO userBankMapVO) { // 开户成功 MConsumerBankMapVO mvo =
	 * mBaseConsumerBankMapServiceImpl.query_consumer_bank_vo(personalNetworkVO.getId());
	 * log.info("个人开户名称={}开户账号={}", personalNetworkVO.getConsumer_name(),
	 * openAccountVO.getAccountNo()); return
	 * consumerBankMapServiceImpl.consumerBankMapUpdate( new
	 * MConsumerBankMappingEntityPO(mvo.getId(), personalNetworkVO.getId(), null,
	 * null, openAccountVO.getAccountNo(), MAccountNumStatus.OPENED, null,
	 * userBankMapVO.getCard_num(), null, null, null,
	 * MSystemConstants.CONSUMER_NATURE_PERSON, new Date(),
	 * openAccountVO.getBankAccountNo())); }
	 */

	/** 用户切换使用的渠道类型 **/
	public ResultBooleanVO changeTradeMemCode(Long consumerId, String relationNum) {
//		log.info("用户切换使用的渠道类型consumerId={},relationNum={}", consumerId, relationNum);
//		BaseVO baseVO = accountService.valAccountForChange(String.valueOf(consumerId));
//		if (!baseVO.isSuccess()) {
//			log.info("用户不能切换渠道 consumerId={}", consumerId);
//			return new ResultBooleanVO("sx.consumer.can.not.change.channel.type");
//		}
//		// 锁定子账户信息
//		ResultBooleanVO result = lockAccountNo(consumerId);
//		if (!result.isSuccess()) {
//			log.info("锁定子账户失败，切换渠道操作终止error={},consumerId={}", result.getMsg(), consumerId);
//			return result;
//		}
//		// 复制数据
//		result = mConsumerBankMapBizImpl.personChangeChannelCopyBankInfo(consumerId, relationNum);
//		if (!result.isSuccess()) {
//			log.error("用户切换使用的渠道类型-复制用户银行卡信息-失败consumerId={},relationNum={}", consumerId, relationNum);
//			return result;
//		}
//		try {
//			//
//			baseVO = accountService.accountChangeChannel(String.valueOf(consumerId), webServiceUtils.queryAccountNo(consumerId), webServiceUtils.queryBranchAccountNo(consumerId), relationNum);
//			if (!baseVO.isSuccess()) {
//				log.info("切换渠道失败consumerId={},relationNum={}", consumerId, relationNum);
//				return new ResultBooleanVO("sx.consumer.change.channel.type.error");
//			}
//		} catch (Exception e) {
//			log.error("切换子账户异常error={}", e);
//			// 解锁子账户信息
//			lockAccountNo(consumerId);
//			return new ResultBooleanVO("sx.consumer.change.channel.type.error");
//		}
//
//		// 切换渠道
//		result = mConsumerDataRelationBizImpl.changeTradeMemCode(consumerId, relationNum, MConsumerDataRelationType.CONSUMER_PERSON_CHANNEL_TYPE);
//		if (!result.isSuccess()) {
//			log.info("用户切换渠道类型失败consumerId={},relationNum={}", consumerId, relationNum);
//			// 切换失败,通知公司端，切换回原来的数据
//			// 获取原来的渠道
//			MConsumerDataRelationVO relationVO = mConsumerDataRelationBizImpl.query_by_consumer_id_and_relation_type(consumerId, MConsumerDataRelationType.CONSUMER_PERSON_CHANNEL_TYPE).getObjVo();
//			// 获取原来的银行信息
//			MConsumerBankMapVO usedBankMapVO = mBaseConsumerBankMapServiceImpl.query_consumer_bank_vo(consumerId, relationNum);
//			// 通知公司端
//			accountService.accountChangeChannel(String.valueOf(consumerId), usedBankMapVO.getAccount_no(), usedBankMapVO.getBank_account_no(), relationVO.getRelation_string_num());
//			return result;
//		}
//		// 解锁子账户信息
//		result = unLockAccountNo(consumerId);
//		if (!result.isSuccess()) {
//			log.info("锁定子账户失败，切换渠道操作终止error={},consumerId={}", result.getMsg(), consumerId);
//			return result;
//		}
//		return result;
		return null;
	}

	/** 跳转到切换渠道界面 */
	public void changeTypeView(ViewAndModel model, Long consumerId) {
		log.info("跳转到切换渠道界面consumerId={}", consumerId);
		model.setViewName("");
		Boolean canChange = null;
		// 判断能否切换渠道
		if (null == consumerId) {
			canChange = false;
		} else {
			//BaseVO baseVO = accountService.valAccountForChange(String.valueOf(consumerId));
			//canChange = baseVO.isSuccess();
		}
		model.addObject("canChange", canChange);
		// 获取能够切换的数据
		log.error("获取能够切换的数据consumerId={}", consumerId);
		MConsumerDataRelationForm relationForm = new MConsumerDataRelationForm();
		relationForm.setConsumer_id(consumerId);
		relationForm.setRelation_type(MConsumerDataRelationType.CONSUMER_PERSON_CHANNEL_TYPE);
		ResultListVO<MConsumerDataRelationVO> listResult = mConsumerDataRelationBizImpl.queryList(relationForm);

		List<MConsumerDataRelationVO> canChangeList = new ArrayList<>();
		for (MConsumerDataRelationVO relationVO : listResult.getData()) {
			// 判断渠道是否设置工资卡，没有设置工资卡（默认使用的卡）的不能切换
			MConsumerBankMapVO bankMapVO = mBaseConsumerBankMapServiceImpl.query_consumer_bank_vo(consumerId, relationVO.getRelation_string_num());
			if (null != bankMapVO) {
				canChangeList.add(relationVO);
			}
		}
		model.addObject("canChangeList", canChangeList);
	}

	/** 跳转到开通子账户界面 */
	public void openAccountView(ViewAndModel model, Long consumerId, String channelType) {
		log.info("跳转到开通子账户界面consumerId={}", consumerId);
		model.setViewName("");
		// 查询用户 channelType 下的所有 银行信息
		ResultListVO<MConsumerBankMapVO> resultList = mBaseConsumerBankMapServiceImpl.query_bank_list_by_consumer_id(consumerId, channelType);

		List<MConsumerBankMapVO> bankMapList = new ArrayList<>();
		for (MConsumerBankMapVO bankMapVO : resultList.getData()) {
			// 未开户的加入集合
			if (StringUtils.isBlank(bankMapVO.getAccount_no()) && StringUtils.isBlank(bankMapVO.getBank_account_no())) {
				bankMapList.add(bankMapVO);
			}
		}
		// 数据带入界面
		model.addObject("bankMapList", bankMapList);
	}

	/** 开通华夏交易会员代码(华夏二代接口开户) */
	public ResultVerifyVO<MVerifOpenAccountVO> accountInfoHuaxia02(Long[] ids) {
		log.debug("华夏二代接口开户 ids={}", NumberUtil.arrayToStr(ids));
		if (null == ids || 0 == ids.length) {
			log.info("开户失败，ids为空");
			return new ResultVerifyVO<>("m.parameter.is.null");
		}
		// 查询所有总行信息
		Map<String, MPayBankVO> payMap = MCacheListener.getProvinceMap();
		StringBuilder error = new StringBuilder();
		// 查询用户信息
		for (Long consumerId : ids) {
			log.info("公司开户查询公司基本信息companyId={}", consumerId);
			MPersonalConsumerNetworkVO networkVO = this.mNetworkPersonConsumerBizImpl.get_consumer_byId(consumerId).getObjVo();
			if (null != networkVO) {
				// 查看是否使用过华夏二代开户
				log.info("判断个人用户是否开过户consumerId={}", consumerId);
				synchronized (this) {
					if (isOpeanAccountHX02(consumerId).isSuccess()) {
						error.append(networkVO.getConsumer_name()).append("已经开通华夏交易会员代码").append("\n");
						log.info("个人用户开户失败，账户信息已经存在consumerId={}", consumerId);
						continue;
					}
					log.info("调用开户接口consumerId={}", consumerId);
					// 调用开户接口
					ResultObjectVO<B2BOpenAccountVO> tradeMemCodeResult = opeanAccountHX02(networkVO, payMap, MSystemConstants.CHANNEL_TYPE_HXBV2);// 调用开户接口
					if (!tradeMemCodeResult.isSuccess()) {
						error.append(networkVO.getConsumer_name()).append(tradeMemCodeResult.getMsg()).append("\n");
						log.info("调用开户接口失败consumerId={},", consumerId, tradeMemCodeResult.getMsg());
						continue;
					}
					B2BOpenAccountVO accountVO = tradeMemCodeResult.getObjVo();
					log.info("个人用户开户信息用户关系库accountVO={},consumerId={}", accountVO, consumerId);
					// 开户信息入库
					ResultBooleanVO result = mConsumerDataRelationBizImpl.insertOpenAccountVO(accountVO, consumerId);
					if (!result.isSuccess()) {
						log.info("个人用户开户信息用户关系库consumerId={},error={}", consumerId, result.getMsg());
						error.append(networkVO.getConsumer_name()).append("开户成功，入库错误").append("\n");
						continue;
					}
					// 扩展信息入库
					log.info("修改个人用户信息扩展库数据OPENED:consumerId={}", consumerId);
					result = consumerOperationInfoServiceImpl.updateHuaxia02AccountStatus(networkVO.getId(), MAccountNumStatus.OPENED);
					if (!result.isSuccess()) {
						log.info("修改个人用户信息扩展库失败:error={}", result.getMsg());
						error.append(networkVO.getConsumer_name()).append("开户成功，入扩展信息库错误").append("\n");
						continue;
					}
					// 调用支付中心
					BaseVO baseVO = null;
					try {
//						log.info("通知个人用户段开户信息accountNo={},bankAccountNo={},consumerId={}", accountVO.getAccountNo(), accountVO.getBankAccountNo(), consumerId);
//						baseVO = accountService.createAccount(accountVO.getAccountNo(), accountVO.getBankAccountNo(), String.valueOf(consumerId));
//						if (!baseVO.isSuccess()) {
//							log.info("通知个人用户段开户信息consumerId={},error={}", consumerId, baseVO.getMsg());
//							error.append(networkVO.getConsumer_name()).append("开户,入库成功，通知支付中心异常").append("\n");
//						}
					} catch (Exception e) {
						log.error("华夏二期开通子账户，通知支付中心异常error={}", e);
						error.append(networkVO.getConsumer_name()).append("开户,入库成功，通知支付中心异常").append("\n");
					}
				}
			}
		}
		if (error.length() > 0) {
			log.error("个人用户开户异常error={}", error.toString());
			return new ResultVerifyVO<>(false, error.toString(), null, null);
		}
		return new ResultVerifyVO<>();
	}

	/** 开通华夏交易会员代码(无卡开户，有卡当时是为了兼容一期代码) */
	public ResultVerifyVO<MVerifOpenAccountVO> openAccountsNoCard(Long[] ids) {
		log.debug("华夏二代接口开户 ids={}", NumberUtil.arrayToStr(ids));
		if (null == ids || 0 == ids.length) {
			log.info("开户失败，ids为空");
			return new ResultVerifyVO<>("m.parameter.is.null");
		}
		// 查询所有总行信息
		Map<String, MPayBankVO> payMap = MCacheListener.getProvinceMap();
		StringBuilder error = new StringBuilder();
		// 查询用户信息
		for (Long consumerId : ids) {
			log.info("公司开户查询公司基本信息companyId={}", consumerId);
			MPersonalConsumerNetworkVO networkVO = this.mNetworkPersonConsumerBizImpl.get_consumer_byId(consumerId).getObjVo();
			if (null != networkVO) {
				// 查看是否使用过华夏二代开户
				log.info("判断个人用户是否开过户consumerId={}", consumerId);
				synchronized (this) {
					if (isOpeanAccountHX02(consumerId).isSuccess()) {
						error.append(networkVO.getConsumer_name()).append("已经开通华夏交易会员代码").append("\n");
						log.info("个人用户开户失败，账户信息已经存在consumerId={}", consumerId);
						continue;
					}
					log.info("调用开户接口consumerId={}", consumerId);
					// 调用开户接口
					ResultObjectVO<B2BOpenAccountVO> tradeMemCodeResult = openAccountsNoCard(networkVO, payMap, MSystemConstants.CHANNEL_TYPE_HXBV2);// 调用开户接口
					if (!tradeMemCodeResult.isSuccess()) {
						error.append(networkVO.getConsumer_name()).append(tradeMemCodeResult.getMsg()).append("\n");
						log.info("调用开户接口失败consumerId={},", consumerId, tradeMemCodeResult.getMsg());
						continue;
					}
					B2BOpenAccountVO accountVO = tradeMemCodeResult.getObjVo();
					log.info("个人用户开户信息用户关系库accountVO={},consumerId={}", accountVO, consumerId);
					// 开户信息入库
					ResultBooleanVO result = mConsumerDataRelationBizImpl.insertOpenAccountVO(accountVO, consumerId);
					if (!result.isSuccess()) {
						log.info("个人用户开户信息用户关系库consumerId={},error={}", consumerId, result.getMsg());
						error.append(networkVO.getConsumer_name()).append("开户成功，入库错误").append("\n");
						continue;
					}
					// 扩展信息入库
					log.info("修改个人用户信息扩展库数据OPENED:consumerId={}", consumerId);
					result = consumerOperationInfoServiceImpl.updateHuaxia02AccountStatus(networkVO.getId(), MAccountNumStatus.OPENED);
					if (!result.isSuccess()) {
						log.info("修改个人用户信息扩展库失败:error={}", result.getMsg());
						error.append(networkVO.getConsumer_name()).append("开户成功，入扩展信息库错误").append("\n");
						continue;
					}
					// 调用支付中心
					BaseVO baseVO = null;
					try {
//						log.info("通知个人用户段开户信息accountNo={},bankAccountNo={},consumerId={}", accountVO.getAccountNo(), accountVO.getBankAccountNo(), consumerId);
//						baseVO = accountService.createAccount(accountVO.getAccountNo(), accountVO.getBankAccountNo(), String.valueOf(consumerId));
//						if (!baseVO.isSuccess()) {
//							log.info("通知个人用户段开户信息consumerId={},error={}", consumerId, baseVO.getMsg());
//							error.append(networkVO.getConsumer_name()).append("开户,入库成功，通知支付中心异常").append("\n");
//						}
					} catch (Exception e) {
						log.error("华夏二期开通子账户，通知支付中心异常error={}", e);
						error.append(networkVO.getConsumer_name()).append("开户,入库成功，通知支付中心异常").append("\n");
					}
				}
			}
		}
		if (error.length() > 0) {
			log.error("个人用户开户异常error={}", error.toString());
			return new ResultVerifyVO<>(false, error.toString(), null, null);
		}
		return new ResultVerifyVO<>();
	}

	/** 开通华夏子账户（单个） **/
	private ResultObjectVO<B2BOpenAccountVO> opeanAccountHX02(MPersonalConsumerNetworkVO networkVO, Map<String, MPayBankVO> payMap, String channelName) {
		log.info("开通华夏子账户channelName={},networkVO={}", channelName, networkVO);
		if (StringUtils.isBlank(channelName) && !MSystemConstants.CHANNEL_TYPE_HXBV2.equals(channelName)) {
			return new ResultObjectVO<>("sx.consumer.open.account.channel.type.is.error");
		}
		// 组织Map类型
		MConsumerBankMapVO bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumerBankMap_for_manage(networkVO.getId(), null);
		MPayBankVO payVO = payMap.get(bankMapVO.getCls_bank_name());
		if (null == payVO) {
			log.info("consumer_name={}系统目前不支持cls_bank_name={}", networkVO.getConsumer_name(), bankMapVO.getCls_bank_name());
			return new ResultObjectVO<>(false, null, "开户失败,系统目前不支持'" + bankMapVO.getCls_bank_name() + "'");
		}
		bankMapVO.setCls_bank_name(payVO.getHuaxia_bank());
		if (null == bankMapVO || StringUtils.isBlank(bankMapVO.getCard_num())) {
			log.info(" 用户没有绑定银行卡 networkVO={}", networkVO);
			return new ResultObjectVO<>("m.user.status.bank.info.cardnum.is.null");
		}
		// 生产开户类
//		OpenAccountForm form = ClassPackUtil.createOpenAccountForm(networkVO, bankMapVO, cache, channelName);
//
//		log.info("生成开通交易会员代码form ={}", form);
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.huaxia02TradeUrl(), ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(form), "UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("返回开通交易会员代码结果 httpResult={}", httpResult.getHttpresult());
//				B2BOpenAccountVO accountVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BOpenAccountVO.class);
//				log.info("个人开户返回结果accountVO={}", accountVO);
//				if (accountVO.isSuccess()) {
//					accountVO.setAccountNo(form.getAccountNo());
//					accountVO.setBankAccountNo(form.getBankAccountNo());
//					return new ResultObjectVO<>(accountVO);
//				} else {
//					return new ResultObjectVO<>(false, null, accountVO.getMsg());
//				}
//			}
//		} catch (Exception e) {
//			log.error("开通交易会员代码http异常error={}", e);
//		}
		return new ResultObjectVO<>("sx.consumer.bank.trade.mem.code.open.fail");
	}

	/** 开通华夏子账户（单个） **/
	private ResultObjectVO<B2BOpenAccountVO> openAccountsNoCard(MPersonalConsumerNetworkVO networkVO, Map<String, MPayBankVO> payMap, String channelName) {
		log.info("开通华夏子账户channelName={},networkVO={}", channelName, networkVO);
		if (StringUtils.isBlank(channelName) && !MSystemConstants.CHANNEL_TYPE_HXBV2.equals(channelName)) {
			return new ResultObjectVO<>("sx.consumer.open.account.channel.type.is.error");
		}
//		OpenAccountForm form = ClassPackUtil.createOpenAccountNoCardForm(networkVO, cache, channelName);
//		log.info("生成开通交易会员代码form ={}", form);
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.huaxia02TradeUrl(), ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(form), "UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("返回开通交易会员代码结果 httpResult={}", httpResult.getHttpresult());
//				B2BOpenAccountVO accountVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BOpenAccountVO.class);
//				log.info("个人开户返回结果accountVO={}", accountVO);
//				if (accountVO.isSuccess()) {
//					accountVO.setAccountNo(form.getAccountNo());
//					accountVO.setBankAccountNo(form.getBankAccountNo());
//					return new ResultObjectVO<>(accountVO);
//				} else {
//					return new ResultObjectVO<>(false, null, accountVO.getMsg());
//				}
//			}
//		} catch (Exception e) {
//			log.error("开通交易会员代码http异常error={}", e);
//		}
		return new ResultObjectVO<>("sx.consumer.bank.trade.mem.code.open.fail");

	}

	/** 判断个人是否开通交易会员代码 **/
	public ResultBooleanVO isOpeanAccountHX02(Long consumer_id) {
		log.info("判断是否开通交易会员代码consumer_id={}", consumer_id);
		MConsumerDataRelationVO relationVO = mConsumerDataRelationBizImpl.query_by_consumer_id_and_relation_type(consumer_id, MConsumerDataRelationType.PERSON_MEMBER_CODE_HUAXIA_02).getObjVo();
		if (null != relationVO) {
			return new ResultBooleanVO();
		} else {
			return new ResultBooleanVO(false, null, null);
		}
	}

	// 解除出入金卡
	public ResultBooleanVO relieveBankCard(Long consumer_id, Long bank_map_id, MConsumerLoginVO loginVO) {
		log.info(" 解绑出入金卡consumer_id={}", consumer_id);
		// 获取银行信息
		MConsumerBankMapVO bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumer_bank_map_by_id(bank_map_id).getObjVo();
		return consumerWebServiceUtil.relieveBankOutCard(consumer_id, bankMapVO, loginVO);
	}

	/** 解绑出入金卡 **/
	public ResultBooleanVO relieveBankDefaultCard(Long consumer_id, MConsumerBankMapVO bankMapVO) {
		// 解除出入金卡
		ResultBooleanVO result = relieveBankCardOper(consumer_id, bankMapVO);
		if (!result.isSuccess()) {
			log.info(" 解绑失败consumer_id={},error={}", consumer_id, result.getMsg());
			return result;
		}
		// 扩展信息入库
		log.info("解绑成功信息入库consumer_id={}", consumer_id);
		result = consumerOperationInfoServiceImpl.updateHuaxia02BindCardStatus(consumer_id, MBindCardStatus.RELIEVE);
		if (!result.isSuccess()) {
			return result;
		}
		log.info("解绑成功修改银行卡信息consumer_id={},bank_map_id={}", bankMapVO.getId());
		// 修改银行卡的状态
		return relieveCardBindSuccess(consumer_id, bankMapVO);
	}

	// 批量绑定出入金卡
	public ResultBooleanVO bindBatchBankCard(Long[] consumer_ids) {
		if (null == consumer_ids || consumer_ids.length == 0) {
			return new ResultBooleanVO("m.parameter.is.null");
		}
		ResultBooleanVO result = null;
		// 消息类
		MsgVO msg = new MsgVO();
		// 个人用户银行信息
		MConsumerBankMapVO bankMapVO = null;
		for (Long consumer_id : consumer_ids) {
			try {
				bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumerBankMap_for_manage(consumer_id, null);
				result = bindBankCard(consumer_id, bankMapVO.getId());
				if (!result.isSuccess()) {
					MPersonalConsumerNetworkVO networkVO = this.mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_id).getObjVo();
					log.info("绑卡错误consumer_id={},consumer_name={},msg={}", consumer_id, networkVO.getConsumer_name(), result.getMsg());
					msg.appendDirectly(networkVO.getConsumer_name()).appendDirectly(":绑卡失败").appendDirectly(result.getMsg());
				}
			} catch (Exception e) {
				log.error("获取个人用户银行信息异常consumer_id={},error={}", consumer_id, e);
			}
		}
		if (msg.getError().length() > 0) {
			result = new ResultBooleanVO(false, null, msg.getError().toString());
		} else {
			result = new ResultBooleanVO();
		}
		return result;
	}

	// 绑定出入金卡
	public ResultBooleanVO bindBankCard(Long consumer_id, Long bank_map_id) {
		log.info("绑定出入金卡consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		// 判断用户能否绑卡
		ResultBooleanVO result = bindBankCardValidate(consumer_id, bank_map_id);
		if (!result.isSuccess()) {
			log.info("用户不能绑卡consumer_id={},bank_map_id={},error={}", consumer_id, bank_map_id, result.getMsg());
			return result;
		}
		// 绑卡
		result = bindBankCardOper(consumer_id, bank_map_id);
		if (!result.isSuccess()) {
			log.info("用户绑卡失败consumer_id={},bank_map_id={},error={}", consumer_id, bank_map_id, result.getMsg());
			return result;
		}
		// 扩展信息入库
		log.info("绑卡成功，信息进入扩展库consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		result = consumerOperationInfoServiceImpl.updateHuaxia02BindCardStatus(consumer_id, MBindCardStatus.BIND);
		if (!result.isSuccess()) {
			log.info("绑卡成功，信息进入扩展库失败 consumer_id={},bank_map_id={},error={}", consumer_id, bank_map_id, result.getMsg());
			return result;
		}
		// 子账号、摊位号信息 进入有银行信息表
		return bankCardBindSuccess(consumer_id, bank_map_id);
	}

	// 批量绑定出金卡
	public ResultBooleanVO bindBatchBankOutCard(Long[] consumer_ids) {
		if (null == consumer_ids || consumer_ids.length == 0) {
			return new ResultBooleanVO("m.parameter.is.null");
		}
		ResultBooleanVO result = null;
		// 消息类
		MsgVO msg = new MsgVO();
		// 个人用户银行信息
		MConsumerBankMapVO bankMapVO = null;
		for (Long consumer_id : consumer_ids) {
			try {
				bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumerBankMap_for_manage(consumer_id, null);
				result = bindBankOutCard(consumer_id, MOutCardType.OUT_CARD_ONE, bankMapVO.getId());
				if (!result.isSuccess()) {
					MPersonalConsumerNetworkVO networkVO = this.mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_id).getObjVo();
					log.info("绑卡错误consumer_id={},consumer_name={},msg={}", consumer_id, networkVO.getConsumer_name(), result.getMsg());
					msg.appendDirectly(networkVO.getConsumer_name()).appendDirectly(":绑卡失败").appendDirectly(result.getMsg());
				}
			} catch (Exception e) {
				log.error("获取个人用户银行信息异常consumer_id={},error={}", consumer_id, e);
			}
		}
		if (msg.getError().length() > 0) {
			result = new ResultBooleanVO(false, null, msg.getError().toString());
		} else {
			result = new ResultBooleanVO();
		}
		return result;
	}

	// 绑定出金卡
	public ResultBooleanVO bindBankOutCard(Long consumer_id, MOutCardType outCardType, Long bank_map_id) {
		if (null == bank_map_id) {
			return new ResultBooleanVO(false, null, "请选择需要绑定的银行卡");
		}
		log.info("绑定出金卡consumer_id={},outCardType={},bank_map_id={}", consumer_id, outCardType, bank_map_id);
		if (null == outCardType) {
			log.info("绑定出金卡consumer_id={},outCardType={}为空,bank_map_id={}", consumer_id, outCardType, bank_map_id);
			return new ResultBooleanVO(false, null, "请选择出金卡类型");
		}
		// 判断用户能否绑卡
		ResultBooleanVO result = consumerWebServiceUtil.bindBankOutCardValidate(consumer_id, outCardType, bank_map_id);
		if (!result.isSuccess()) {
			log.info("用户不能绑卡consumer_id={},bank_map_id={},error={}", consumer_id, bank_map_id, result.getMsg());
			return result;
		}
		// // 绑卡
		result = bindBankOutCardOper(consumer_id, bank_map_id, outCardType);
		if (!result.isSuccess()) {
			log.info("用户绑卡失败consumer_id={},bank_map_id={},error={}", consumer_id, bank_map_id, result.getMsg());
			return result;
		}
		// 扩展信息入库
		log.info("绑卡成功，信息进入扩展库consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		result = consumerOperationInfoServiceImpl.updateOutCardStatus(consumer_id, outCardType, MBindCardStatus.BIND);
		if (!result.isSuccess()) {
			log.info("绑卡成功，信息进入扩展库失败 consumer_id={},bank_map_id={},outCardType={},error={}", consumer_id, bank_map_id, outCardType, result.getMsg());
			return result;
		}
		// 子账号、摊位号信息 进入有银行信息表
		return bankOutCardBindSuccess(consumer_id, outCardType, bank_map_id);
	}

	/** 绑卡成功后续操作 **/
	private ResultBooleanVO bankCardBindSuccess(Long consumer_id, Long bank_map_id) {
		log.info("绑卡成功，修改银行卡信息consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		// 查询银行信息
		MConsumerBankMapVO bankMapVO = mBaseConsumerBankMapServiceImpl.query_consumer_bank_map_by_id(bank_map_id).getObjVo();
		MConsumerBankMapForm bankMapForm = new MConsumerBankMapForm();
		bankMapForm.setId(bank_map_id);
		bankMapForm.setAccount_no(webServiceUtils.queryAccountNo(consumer_id));
		bankMapForm.setBank_account_no(webServiceUtils.queryBranchAccountNo(consumer_id));
		bankMapForm.setAccount_no_status(MAccountNumStatus.OPENED);
		bankMapForm.setTrade_mem_code(webServiceUtils.queryTradeMemberCode(consumer_id));
		// 是华夏银行卡，（需要第二天华夏人员确认后才能使用）
		if (WebServiceUtil.configHuaXiaBank(bankMapVO.getCls_bank_name())) {
			bankMapForm.setStatus(MUsingStatus.DEFAULT_USED_WAIT);
		} else {
			bankMapForm.setStatus(MUsingStatus.DEFAULT_USED);
		}
		bankMapForm.setChannel_status(MDataStatusType.DATA_AVAILABLE);
		// 出入金卡类型
		bankMapForm.setOut_card_type(MOutCardType.IN_OUT_CARD);
		bankMapForm.setOpen_account_time(new Date());
		// 修改银行信息
		return consumerBankMapServiceImpl.consumerBankMapUpdate(bankMapForm);
	}

	/** 绑卡成功后续操作 **/
	private ResultBooleanVO bankOutCardBindSuccess(Long consumer_id, MOutCardType outCardType, Long bank_map_id) {
		log.info("绑卡成功，修改银行卡信息consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		// 查询银行信息
		MConsumerBankMapVO bankMapVO = mBaseConsumerBankMapServiceImpl.query_consumer_bank_map_by_id(bank_map_id).getObjVo();
		MConsumerBankMapForm bankMapForm = new MConsumerBankMapForm();
		bankMapForm.setId(bank_map_id);
		bankMapForm.setAccount_no(webServiceUtils.queryAccountNo(consumer_id));
		bankMapForm.setBank_account_no(webServiceUtils.queryBranchAccountNo(consumer_id));
		bankMapForm.setAccount_no_status(MAccountNumStatus.OPENED);
		bankMapForm.setTrade_mem_code(webServiceUtils.queryTradeMemberCode(consumer_id));
		// 是华夏银行卡，（需要第二天华夏人员确认后才能使用）
		// if (WebServiceUtil.configHuaXiaBank(bankMapVO.getCls_bank_name())) {
		if (MUsingStatus.DEFAULT_USED.equals(bankMapVO.getStatus()) || MUsingStatus.DEFAULT_USED_WAIT.equals(bankMapVO.getStatus())) {
			bankMapForm.setStatus(MUsingStatus.DEFAULT_USED_WAIT);
		} else if (MUsingStatus.CAN_USED.equals(bankMapVO.getStatus()) || MUsingStatus.CAN_USED_WAIT.equals(bankMapVO.getStatus())) {
			bankMapForm.setStatus(MUsingStatus.CAN_USED_WAIT);
		} else {
			bankMapForm.setStatus(MUsingStatus.CAN_USED_WAIT);
		}
		// } else {
		// bankMapForm.setStatus(MUsingStatus.DEFAULT_USED);
		// }
		bankMapForm.setChannel_status(MDataStatusType.DATA_AVAILABLE);
		// 出金卡类型
		bankMapForm.setOut_card_type(outCardType);
		bankMapForm.setOpen_account_time(new Date());
		// 修改银行信息
		return consumerBankMapServiceImpl.consumerBankMapUpdate(bankMapForm);
	}


	// 绑卡前的验证
	public ResultBooleanVO bindBankCardValidate(Long consumer_id, Long bank_map_id) {
		//
		log.info("绑定的出入金卡前用户信息验证，consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		// 判断是否已经进行了三要素要争
		MConsumerBankMapVO bankMapVO = mBaseConsumerBankMapServiceImpl.query_consumer_bank_vo(consumer_id);
		if (null == bankMapVO) {
			return new ResultBooleanVO();
		}
		if (MUserInfoBankValidate.VALIDATE_FAILURE.equals(bankMapVO.getKey_validate())) {
			log.info("绑定的出入金卡三要素验证失败，不能绑定consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
			return new ResultBooleanVO(false, null, "绑定的出入金卡三要素验证失败，不能绑定");
		} else if (MUserInfoBankValidate.VALIDATE_NOT_YET.equals(bankMapVO.getKey_validate())) {
			log.info("绑定的出入金卡没有进行三要素验证，不能绑定consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
			return new ResultBooleanVO(false, null, "绑定的出入金卡没有进行三要素验证，不能绑定");
		}
		// 出入金只能是主卡
		if (null != bankMapVO.getId()) {
			if (!bankMapVO.getId().equals(bank_map_id)) {
				log.info("绑定的出入金卡不是主卡，不能绑定bankMapVO={},bank_map_id={}", bankMapVO, bank_map_id);
				return new ResultBooleanVO(false, null, "有主卡存在，不能绑定非主卡的银行卡");
			} // 绑定的是主卡
			if (null != bankMapVO.getOut_card_type()) {
				if (MOutCardType.NOT_BIND_CARD.equals(bankMapVO.getOut_card_type())) {
					return new ResultBooleanVO();
				} else if (MOutCardType.IN_OUT_CARD.equals(bankMapVO.getOut_card_type())) {
					log.info("此卡已经绑定为出入金卡bankMapVO={}", bankMapVO);
					return new ResultBooleanVO(false, null, "此卡已经绑定为出入金卡");
				} else if (MOutCardType.OUT_CARD_ONE.equals(bankMapVO.getOut_card_type())) {
					log.info("此卡已经绑定为出金卡一bankMapVO={}", bankMapVO);
					return new ResultBooleanVO(false, null, "此卡已经绑定为出金卡一");
				} else if (MOutCardType.OUT_CARD_TWO.equals(bankMapVO.getOut_card_type())) {
					log.info("此卡已经绑定为出金卡二bankMapVO={}", bankMapVO);
					return new ResultBooleanVO(false, null, "此卡已经绑定为出金卡二");
				} else if (MOutCardType.OUT_CARD_THREE.equals(bankMapVO.getOut_card_type())) {
					log.info("此卡已经绑定为出金卡三bankMapVO={}", bankMapVO);
					return new ResultBooleanVO(false, null, "此卡已经绑定为出金卡三");
				}
			}
			return new ResultBooleanVO();
		}

		// 没有默认的主卡，返回true
		return new ResultBooleanVO();
	}

	// 绑定出金卡前的验证
	public ResultBooleanVO bindBankOutCardValidate(Long consumer_id, MOutCardType outCardType, Long bank_map_id) {
		//
		log.info("绑定的出入金卡前用户信息验证，consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		ResultListVO<MConsumerBankMapVO> bankListMapVO = mBaseConsumerBankMapServiceImpl.queryBankListByConsumerId(consumer_id);
		if (!bankListMapVO.isSuccess()) {
			log.info("consumer_id={}绑定出金卡前的验证失败,不能绑定出金卡。msg={}", consumer_id, bankListMapVO.getMsg());
			return new ResultBooleanVO(false, null, bankListMapVO.getMsg() + ",不能绑定出金卡。");
		}
		// 直接成功
		if (null == bankListMapVO.getData() || bankListMapVO.getData().isEmpty()) {
			log.info("consumer_id={}绑定出金卡前的验证成功", consumer_id);
			return new ResultBooleanVO();
		}
		// 验证，只能有三个出金卡
		for (MConsumerBankMapVO bankMapVO : bankListMapVO.getData()) {
			if (MDataStatusType.DATA_AVAILABLE.equals(bankMapVO.getChannel_status())
					&& ((MUsingStatus.CAN_USED.equals(bankMapVO.getStatus()) || MUsingStatus.CAN_USED_WAIT.equals(bankMapVO.getStatus())) && outCardType.equals(bankMapVO.getOut_card_type())
							&& (MUsingStatus.DEFAULT_USED_WAIT.equals(bankMapVO.getStatus()) || MUsingStatus.DEFAULT_USED.equals(bankMapVO.getStatus()))
							&& outCardType.equals(bankMapVO.getOut_card_type()))) {
				log.info("consumer_id={}已经绑定出金卡,不能绑定出金卡bankMapVO={}", consumer_id, bankMapVO);
				return new ResultBooleanVO(false, null, "已经绑定出金卡,不能绑定出金卡。");
			}
		}
		// 可以绑卡
		return new ResultBooleanVO();
	}

	// 解绑出入金卡操作
	public ResultBooleanVO relieveBankCardOper(Long consumer_id, MConsumerBankMapVO bankMapVO) {
		log.info("解绑用户银行卡consumer_id={},bank_map_id={}", consumer_id, bankMapVO.getId());
		// 获取用户、银行信息
		MPersonalConsumerNetworkVO consumerVO = mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_id).getObjVo();
//		// 生成解绑出入金form
//		BindBankCardForm cardForm = ClassPackUtil.createRelieveBankCardForm(consumerVO, bankMapVO, webServiceUtils.queryBranchAccountNo(consumer_id),
//				webServiceUtils.queryTradeMemberCode(consumer_id));
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.bindBankCardUrl(), ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(cardForm),
//					"UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("解绑出入金结果 httpResult={}", httpResult.getHttpresult());
//				B2BQueryAccountRssultVO accountResult = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BQueryAccountRssultVO.class);
//				if (!accountResult.isSuccess()) {
//					log.info("解绑失败error={}", accountResult.getMsg());
//					return new ResultBooleanVO(false, "sx.consumer.bank.bind.bank.card.fail", accountResult.getMsg());
//				} else {
//					return new ResultBooleanVO();
//				}
//			}
//		} catch (Exception e) {
//			log.error("绑定出入金账户http异常error={}", e);
//			return new ResultBooleanVO("sx.consumer.bank.bind.bank.card.fail");
//		}
		return new ResultBooleanVO("sx.consumer.bank.bind.bank.card.fail");
	}

	/** 解绑成功后续操作 **/
	private ResultBooleanVO relieveCardBindSuccess(Long consumer_id, MConsumerBankMapVO bankMapVO) {
		log.info("解绑成功修改银行卡信息consumer_id={},bank_map_id={}", bankMapVO.getId());
		// 查询银行信息
		MConsumerBankMapForm bankMapForm = new MConsumerBankMapForm();
		bankMapForm.setId(bankMapVO.getId());
		bankMapForm.setAccount_no(null);
		bankMapForm.setBank_account_no(null);
		bankMapForm.setAccount_no_status(MAccountNumStatus.NOT_OPEN);
		bankMapForm.setTrade_mem_code(null);
		bankMapForm.setStatus(MUsingStatus.DEFAULT_USED);
		// bankMapForm.setStatus(MUsingStatus.CAN_USED);
		bankMapForm.setChannel_status(MDataStatusType.DATA_AVAILABLE);
		bankMapForm.setBank_account_no(null);
		// 修改银行信息
		return consumerBankMapServiceImpl.consumerBankMapUpdateForNull(bankMapForm);
	}

	// 绑卡操作
	private ResultBooleanVO bindBankCardOper(Long consumer_id, Long bank_map_id) {
		log.info("个人用户绑定银行卡操作consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		// 获取用户、银行信息
		MPersonalConsumerNetworkVO consumerVO = mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_id).getObjVo();
		MConsumerBankMapVO bankMapVO = null;
		if (null == bank_map_id) {
			bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumer_bank_vo(consumer_id);
		} else {
			bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumer_bank_map_by_id(bank_map_id).getObjVo();
		}
//		// 生成绑定出入金form
//		BindBankCardForm cardForm = ClassPackUtil.createBindBankCardForm(consumerVO, bankMapVO, webServiceUtils.queryBranchAccountNo(consumer_id), webServiceUtils.queryTradeMemberCode(consumer_id));
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.bindBankCardUrl(), ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(cardForm),
//					"UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("绑定出入金结果 httpResult={}", httpResult.getHttpresult());
//				B2BQueryAccountRssultVO accountResult = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BQueryAccountRssultVO.class);
//				if (!accountResult.isSuccess() && !MSystemConstants.HX_RETURN_FALSE_PASS.equals(accountResult.getMsgcode())) {
//					log.info("绑定失败error={}", accountResult.getMsg());
//					return new ResultBooleanVO(false, "sx.consumer.bank.bind.bank.card.fail", accountResult.getMsg());
//				} else {
//					return new ResultBooleanVO();
//				}
//			}
//		} catch (Exception e) {
//			log.error("绑定出入金账户http异常error={}", e);
//			return new ResultBooleanVO("sx.consumer.bank.bind.bank.card.fail");
//		}
		return new ResultBooleanVO("sx.consumer.bank.bind.bank.card.fail");
	}

	// 绑卡操作
	private ResultBooleanVO bindBankOutCardOper(Long consumer_id, Long bank_map_id, MOutCardType outCardType) {
		log.info("个人用户绑定出金卡操作consumer_id={},bank_map_id={}", consumer_id, bank_map_id);
		// 获取用户、银行信息
		MPersonalConsumerNetworkVO consumerVO = mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_id).getObjVo();
		MConsumerBankMapVO bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumer_bank_map_by_id(bank_map_id).getObjVo();
		bankMapVO.setOut_card_type(outCardType);
//		// 生成绑定出入金form
//		BindBankCardForm cardForm = ClassPackUtil.createBindOutBankCardForm(consumerVO, bankMapVO, webServiceUtils.queryBranchAccountNo(consumer_id),
//				webServiceUtils.queryTradeMemberCode(consumer_id));
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.bindBankOutCardUrl(), ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(cardForm),
//					"UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("绑定出金卡结果 httpResult={}", httpResult.getHttpresult());
//				B2BQueryAccountRssultVO accountResult = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BQueryAccountRssultVO.class);
//				if (!accountResult.isSuccess() && !MSystemConstants.HX_RETURN_FALSE_PASS.equals(accountResult.getMsgcode())) {
//					log.info("绑定出金卡失败error={}", accountResult.getMsg());
//					return new ResultBooleanVO(false, "sx.consumer.bank.bind.bank.out.card.fail", accountResult.getMsg());
//				} else {
//					return new ResultBooleanVO();
//				}
//			}
//		} catch (Exception e) {
//			log.error("绑定出金账户http异常error={}", e);
//			return new ResultBooleanVO("sx.consumer.bank.bind.bank.out.card.fail");
//		}
		return new ResultBooleanVO("sx.consumer.bank.bind.bank.out.card.fail");
	}

	/** 批量子账户信息变更 **/
	public ResultBooleanVO accountInfoChangeBatch(Long[] consumer_ids) {
		if (consumer_ids.length == 0) {
			return new ResultBooleanVO(false, null, "请选择要操作的用户");
		}
		log.info("子账户信息变更consumer_id={}", NumberUtil.arrayToStr(consumer_ids));
		StringBuilder error = new StringBuilder();
		ResultBooleanVO result = null;
		for (Long consumer_id : consumer_ids) {
			MConsumerOperationInfoVO operationVO = consumerOperationInfoServiceImpl.queryByConsumerId(consumer_id).getObjVo();
			MPersonalConsumerNetworkVO consumerVO = mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_id).getObjVo();
			if (!MAccountNumStatus.OPENED.equals(operationVO.getHuaxia02_account_status())) {
				log.info("consumer_name={}未开户，不能进行变更操作", consumerVO.getConsumer_name());
				error.append(consumerVO.getConsumer_name()).append("未开户，不能进行变更操作  \n ");
			} else {
				result = accountInfoChange(consumer_id);
				if (!result.isSuccess()) {
					log.info("consumer_name子账户信息变更失败error={}", consumerVO.getConsumer_name(), result.getMsg());
					error.append(consumerVO.getConsumer_name()).append("子账户信息变更失败  \n ");
				}
			}
		}
		if (error.length() > 0) {
			return new ResultBooleanVO(false, null, error.toString());
		}
		return new ResultBooleanVO();
	}

	/**
	 * 子账户信息变更
	 * 
	 * @param consumer_id
	 * @param tradeMemBerCode
	 * @param accountNo
	 * @return
	 */
	private ResultBooleanVO accountInfoChange(Long consumer_id) {
//		// 查看用户是否提出过修改申请
//		log.info("子账户信息变更consumer_id={}", consumer_id);
//		MPersonalConsumerNetworkVO consumerVO = mNetworkPersonConsumerBizImpl.get_consumer_byId(consumer_id).getObjVo();
//		// 数据封装
//		AccInfoChangeForm changeForm = ClassPackUtil.createAccInfoChangeForm(consumerVO, webServiceUtils.queryTradeMemberCode(consumer_id), webServiceUtils.queryBranchAccountNo(consumer_id));
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.accountInfoChangeUrl(), ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(changeForm),
//					"UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("子账户信息变更 httpResult={}", httpResult.getHttpresult());
//				B2BchangeAccountVO changeAccountVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BchangeAccountVO.class);
//				if (!changeAccountVO.isSuccess()) {
//					return new ResultBooleanVO(false, "sx.consumer.bank.account.info.change", changeAccountVO.getMsg());
//				} else {
//					return new ResultBooleanVO();
//				}
//			}
//		} catch (Exception e) {
//			log.error("子账户信息变更http异常error={}", e);
//			return new ResultBooleanVO("sx.consumer.bank.account.info.change");
//		}
		return new ResultBooleanVO("sx.consumer.bank.account.info.change");
	}

	/** 子账户状态变更 */
	public ResultBooleanVO accountStatusChange(Long consumer_id, String tradeMemBerCode, String accountNo) {
		log.info("子账户状态变更consumer_id={},tradeMemBerCode={},accountNo={}", consumer_id, tradeMemBerCode, accountNo);
//		// 数据封装
//		AccStatusChangeForm changeForm = new AccStatusChangeForm();
//		changeForm.setIsCoerce("0");
//		changeForm.setState(MSystemConstants.ACCOUNT_STATUS_AVAILABLE);
//		changeForm.setTradeMemBerCode(tradeMemBerCode);
//		changeForm.setSubAcc(accountNo);
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.accountStatusChangeUrl(), ContentType.JSON, null, HTTP_TIME_OUT,
//					JackJsonUtil.objToJson(changeForm), "UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("子账户状态变更 httpResult={}", httpResult.getHttpresult());
//				B2BRssultVO statusVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BRssultVO.class);
//				if (!statusVO.isSuccess()) {
//					return new ResultBooleanVO(false, "sx.consumer.bank.account.status.change", statusVO.getMsg());
//				} else {
//					return new ResultBooleanVO();
//				}
//			}
//		} catch (Exception e) {
//			log.error("子账户变更http异常error={}", e);
//			return new ResultBooleanVO("sx.consumer.bank.account.status.change");
//		}
		return new ResultBooleanVO("sx.consumer.bank.account.status.change");
	}
//
//	/** 获取子账户信息 */
//	public B2BQueryAccountVO getAccountInfo(Long consumer_id) {
//		log.info("获取子账户信息失败consumer_id={}", consumer_id);
//		// 数据封装
//		AccInfoQueryForm queryForm = new AccInfoQueryForm();
//		queryForm.setMemBerCode(webServiceUtils.queryTradeMemberCode(consumer_id));
//		queryForm.setSubAccount(webServiceUtils.queryBranchAccountNo(consumer_id));
//		queryForm.setGradeCode("");
//		try {
//			String url = WebServiceUtil.getAccountInfoUrl();
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(url, ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(queryForm), "UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info(" 获取子账户信息 httpResult={}", httpResult.getHttpresult());
//				B2BQueryAccountVO statusVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BQueryAccountVO.class);
//				if (!statusVO.isSuccess()) {
//					log.info("获取子账户信息失败consumer_id={},statusVO={}", consumer_id, statusVO);
//					return statusVO;
//				}
//				return statusVO;
//			}
//		} catch (Exception e) {
//			log.error(" 获取子账户信息http异常error={}", e);
//		}
//		return new B2BQueryAccountVO("sx.consumer.bank.account.get.accountInfo");
//	}

//	/** 绑定信息查询 */
//	public ViewAndModel getAccountBindInfo1(ViewAndModel model, Long consumer_id, String outComeAccountType) {
//		// 数据封装
//		AccBindInfoQueryForm bindForm = new AccBindInfoQueryForm();
//		bindForm.setTradeMemCode(webServiceUtils.queryTradeMemberCode(consumer_id));
//		bindForm.setSubAccount(webServiceUtils.queryBranchAccountNo(consumer_id));
//		bindForm.setOutComeAccountType(StringUtils.isBlank(outComeAccountType) ? "0" : outComeAccountType);
//
//		B2BBindBankCardResultVO statusVO = null;
//		try {
//			String url = WebServiceUtil.getAccountBindInfoUrl();
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(url, ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(bindForm), "UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("绑定信息查询 httpResult={}", httpResult.getHttpresult());
//				statusVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BBindBankCardResultVO.class);
//				model.addObject("bindBankCardVO", statusVO);
//				return model;
//			}
//		} catch (Exception e) {
//			log.error("绑定信息查询http异常error={}", e);
//		}
//		return model;
//	}
//
//	/** 绑定信息查询 */
//	public B2BBindBankCardResultVO getAccountBindInfo(Long consumer_id, String outComeAccountType) {
//		log.info("绑定信息查询consumer_id={},outComeAccountType={}", consumer_id, outComeAccountType);
//		// 数据封装
//		AccBindInfoQueryForm bindForm = new AccBindInfoQueryForm();
//		bindForm.setTradeMemCode(webServiceUtils.queryTradeMemberCode(consumer_id));
//		bindForm.setSubAccount(webServiceUtils.queryBranchAccountNo(consumer_id));
//		bindForm.setOutComeAccountType(StringUtils.isBlank(outComeAccountType) ? "0" : outComeAccountType);
//		try {
//			String url = WebServiceUtil.getAccountBindInfoUrl();
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(url, ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(bindForm), "UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("绑定信息查询 httpResult={}", httpResult.getHttpresult());
//				B2BBindBankCardResultVO statusVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BBindBankCardResultVO.class);
//				if (!statusVO.isSuccess()) {
//					log.info("绑定信息查询失败consumer_id={},statusVO={}", consumer_id, statusVO);
//					return statusVO;
//				}
//				return statusVO;
//			}
//		} catch (Exception e) {
//			log.error("绑定信息查询http异常error={}", e);
//		}
//		return new B2BBindBankCardResultVO("sx.consumer.bank.account.get.bind.accountInfo");
//	}
//
//	/** 子账户余额查询 */
//	public B2BAccountBalanceVO getAccountBalance(Long consumer_id) {
//		log.info("子账户余额查询consumer_id={}", consumer_id);
//		// 数据封装
//		BalanceForm balanceForm = new BalanceForm();
//		balanceForm.setAccountNo(webServiceUtils.queryAccountNo(consumer_id));
//		// 1：子账户,2：实体账户,3：资金监管账户
//		balanceForm.setAccountTpye(MSystemConstants.ACCOUNT_TYPE_1);
//		balanceForm.setBankAccountNo(webServiceUtils.queryBranchAccountNo(consumer_id));
//		balanceForm.setMemBerCode(webServiceUtils.queryTradeMemberCode(consumer_id));
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.getAccountBalanceUrl(), ContentType.JSON, null, HTTP_TIME_OUT, JackJsonUtil.objToJson(balanceForm),
//					"UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("子账户余额查询 httpResult={}", httpResult.getHttpresult());
//				B2BAccountBalanceVO statusVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BAccountBalanceVO.class);
//				if (!statusVO.isSuccess()) {
//					log.info("子账户余额查询失败 statusVO={}", statusVO);
//					return statusVO;
//				}
//				return statusVO;
//			}
//		} catch (Exception e) {
//			log.error("子账户余额查询http异常error={}", e);
//		}
//		return new B2BAccountBalanceVO("sx.consumer.bank.account.balance");
//	}
//
//	/** 账户签约信息查询 */
//	public B2BAccountInfoVO getContractAccountInfo(Long consumer_id) {
//		log.info(" 账户签约信息查询consumer_id={}", consumer_id);
//		ContractAccountForm balanceForm = new ContractAccountForm();
//		balanceForm.setAccountNo(webServiceUtils.queryAccountNo(consumer_id));
//		try {
//			HttpResult httpResult = httpPoolManager.getHttpClient().postAuthorization(WebServiceUtil.getContractAccountInfoUrl(), ContentType.JSON, null, HTTP_TIME_OUT,
//					JackJsonUtil.objToJson(balanceForm), "UTF-8");
//			if (null != httpResult && 200 == httpResult.getStatus()) {
//				log.info("账户签约信息查询 httpResult={}", httpResult.getHttpresult());
//				B2BAccountInfoVO statusVO = JackJsonUtil.jsonToJavaBean(httpResult.getHttpresult(), B2BAccountInfoVO.class);
//				if (!statusVO.isSuccess()) {
//					log.info(" 账户签约信息查询失败，返回信息statusVO={}", statusVO);
//					return statusVO;
//				}
//				return statusVO;
//			}
//		} catch (Exception e) {
//			log.error("账户签约信息查询http异常error={}", e);
//		}
//		return new B2BAccountInfoVO("sx.consumer.bank.b2b.account.info");
//	}

//	/** 锁定用户子账户 */
//	public ResultBooleanVO lockAccountNo(Long consumer_id) {
//		// 查询用户子账号
//		String account_no = webServiceUtils.queryAccountNo(consumer_id);
//		if (StringUtils.isBlank(account_no)) {
//			log.info("用户未开户consumer_id={}", consumer_id);
//			return new ResultBooleanVO("sx.consumer.account.info.not.open");
//		}
//		CAccountInfoEntity accountInfo = new CAccountInfoEntity();
//		accountInfo.setAccount_no(account_no);
//		accountInfo.setStatus(AccountStatus.FORBIDDEN);
//		log.info("开始锁定子账户信息完成consumer_id={}", consumer_id);
//		// 锁定用户子账户
//		int num = accountService.updateAccountInfoByAccountNo(accountInfo);
//		if (num == 0) {
//			log.info("锁定用户子账户失败 consumer_id={}", consumer_id);
//			return new ResultBooleanVO("sx.consumer.lock.account.no");
//		}
//		log.info("锁定子账户信息完成consumer_id={}", consumer_id);
//		return new ResultBooleanVO();
//	}
//
//	/** 锁定用户子账户 */
//	public ResultBooleanVO lockAccountNoForChangeTradeMemCode(Long consumer_id) {
//		// 激活发送短信和邮件
//		log.info("锁定用户子账户consumer_id={}", consumer_id);
//		BaseVO baseVO = accountService.valAccountForChange(String.valueOf(consumer_id));
//		if (!baseVO.isSuccess()) {
//			log.info("用户子账户不能锁定consumer_id={},meg={}", consumer_id, baseVO.getMsg());
//			return new ResultBooleanVO("sx.consumer.account.no.can.not.lock");
//		}
//		// 查询用户子账号
//		String account_no = webServiceUtils.queryAccountNo(consumer_id);
//		if (StringUtils.isBlank(account_no)) {
//			log.info("用户未开户consumer_id={}", consumer_id);
//			return new ResultBooleanVO("sx.consumer.account.info.not.open");
//		}
//		CAccountInfoEntity accountInfo = new CAccountInfoEntity();
//		accountInfo.setAccount_no(account_no);
//		accountInfo.setStatus(AccountStatus.FORBIDDEN);
//		log.info("开始锁定子账户信息完成consumer_id={}", consumer_id);
//		// 锁定用户子账户
//		int num = accountService.updateAccountInfoByAccountNo(accountInfo);
//		if (num == 0) {
//			log.info("锁定用户子账户失败 consumer_id={}", consumer_id);
//			return new ResultBooleanVO("sx.consumer.lock.account.no");
//		}
//		log.info("锁定子账户信息完成consumer_id={}", consumer_id);
//		return new ResultBooleanVO();
//	}
//
//	/** 解锁用户子账户 */
//	public ResultBooleanVO unLockAccountNo(Long consumer_id) {
//		log.info("用户解锁渠道consumer_id={}", consumer_id);
//		// 查询用户子账号
//		String account_no = webServiceUtils.queryAccountNo(consumer_id);
//		if (StringUtils.isBlank(account_no)) {
//			log.info("用户未开户consumer_id={}", consumer_id);
//			return new ResultBooleanVO("sx.consumer.account.info.not.open");
//		}
//		CAccountInfoEntity accountInfo = new CAccountInfoEntity();
//		accountInfo.setAccount_no(account_no);
//		accountInfo.setStatus(AccountStatus.NORMAL);
//		try {
//			// 解锁用户子账户
//			int num = accountService.updateAccountInfoByAccountNo(accountInfo);
//			if (num == 0) {
//				log.info("解锁定用户子账户失败 consumer_id={}", consumer_id);
//				return new ResultBooleanVO("sx.consumer.unlock.account.no");
//			}
//		} catch (Exception e) {
//			log.info("解锁定用户子账户失败 error={}", e);
//			return new ResultBooleanVO("sx.consumer.unlock.account.no");
//		}
//
//		return new ResultBooleanVO();
//	}

	/** 批量转账excel导出 */
	public void exportBatchTransfer(MPersonalConsumerNetworkForm form, HttpServletResponse response, MConsumerLoginVO loginConsumer) {
		// 去掉

		log.info("批量转账excel导出 consumer_id={},consumer_name={},company_id={}", loginConsumer.getConsumer_id(), loginConsumer.getConsumer_name(), form.getCompany_id());
		// 权限次数减少
		MDataAuthorityForm reduceForm = new MDataAuthorityForm();
		reduceForm.setConsumer_id(loginConsumer.getConsumer_id());
		reduceForm.setAuth_value(String.valueOf(form.getCompany_id()));
		reduceForm.setAuthority_path(MDataAuthPath.EXPORT_BATCH_TRANSFER);

		ResultBooleanVO result = dataAuthorityBizImpl.reduceAuth(reduceForm);
		// 权限扣除成功，导出，否则抛出异常
		if (result.isSuccess()) {
			// 添加操作日志
			webLogUtil.addOperLog(null, loginConsumer, MFuncType.SX_MANAGE_CUSTOMER, MLogOperType.EXCEL_ERPORT, "批量转账excel导出 company_id:" + form.getCompany_id());
			if (form.getIds_().length == 0 || null == form.getIds_()[0]) {
				form.setIds_(null);
			}
			Long consumer_num = mNetworkPersonConsumerBizImpl.consumer_num(form);
			form.setLength(consumer_num);

			ResultListVO<MPersonalConsumerVO> resultList = mNetworkPersonConsumerBizImpl.get_consumer_page(form);
			List<MPersonalConsumerVO> dataList = resultList.getData();
			List<MPersonalConsumerVO> excelList = new ArrayList<>(dataList.size());
			for (MPersonalConsumerVO consumerVO : dataList) {
				if (!StringUtils.isBlank(consumerVO.getCard_num_str())) {
					excelList.add(consumerVO);
				}
			}
			ExcelUtils.saveDataToStream(excelList, response);
		} else {
			throw new MRollbackException("权限扣除异常、导出失败");
		}
	}

	/** 用户子账户信息导出 */
	public void exportBatchBankAccountNo(MPersonalConsumerNetworkForm form, HttpServletResponse response, MConsumerLoginVO loginConsumer) {
		log.info("用户子账户信息导入，权限扣除form={}", form);
		// 权限次数减少
		MDataAuthorityForm reduceForm = new MDataAuthorityForm();
		reduceForm.setConsumer_id(loginConsumer.getConsumer_id());
		reduceForm.setAuth_value(String.valueOf(form.getCompany_id()));
		reduceForm.setAuthority_path(MDataAuthPath.EXPORT_BANK_ACCOUNT_NO);

		ResultBooleanVO result = dataAuthorityBizImpl.reduceAuth(reduceForm);
		// 权限扣除成功，导出，否则抛出异常
		if (result.isSuccess()) {

			if (form.getIds_().length == 0 || null == form.getIds_()[0]) {
				form.setIds_(null);
			}
			log.info("用户子账户信息导出 consumer_id={},consumer_name={},company_id={}", loginConsumer.getConsumer_id(), loginConsumer.getConsumer_name(), form.getCompany_id());
			// 添加操作日志
			webLogUtil.addOperLog(null, loginConsumer, MFuncType.SX_MANAGE_CUSTOMER, MLogOperType.EXCEL_ERPORT, "用户子账户信息导出 company_id:" + form.getCompany_id());

			String titleStr = form.getRemark();
			//
			Long consumer_num = mNetworkPersonConsumerBizImpl.consumer_num(form);
			form.setLength(consumer_num);

			ResultListVO<MPersonalConsumerVO> resultList = mNetworkPersonConsumerBizImpl.get_consumer_page(form);
			List<MPersonalConsumerVO> dataList = resultList.getData();
			List<MPersonalConsumerVO> excelList = new ArrayList<>(dataList.size());
			for (MPersonalConsumerVO consumerVO : dataList) {
				if (!StringUtils.isBlank(consumerVO.getBank_account_no_str())) {
					excelList.add(consumerVO);
				}
			}
			ExcelUtils.bankAccountNoStream(excelList, response, titleStr);
		} else {
			throw new MRollbackException("权限扣除异常、导出失败");
		}
	}
}
